package com.nariano.server.services.statistics;

import static com.nariano.server.domain.entities.PopulationType.KNIGTH;
import static com.nariano.server.domain.entities.PopulationType.SOLDIER;

import java.util.HashMap;
import java.util.Map;

import com.nariano.server.domain.entities.PopulationType;

public class PopulationDistribution {
	
	final Map<PopulationType, Integer> distribution;
	int count=0;

	public PopulationDistribution(Map<PopulationType, Integer> distribution) {
		this.distribution = distribution;
		for(Integer v : distribution.values()) {
			count += v;
		}
	}
	
	public PopulationDistribution() {
		this(new HashMap<PopulationType, Integer>());
	}

	public int getPoupulationCount(PopulationType type) {
		Integer count = distribution.get(type);
		return count==null?0:count;
	}
	
	public void addPopulation(PopulationType type, int count) {
		Integer storedCount = distribution.get(type);
		distribution.put(type, storedCount==null?count:storedCount+count);
		this.count += count;
	}

	public int getPoupulationCount() {
		return count;
	}

	public int getWarPower() {
		return getPoupulationCount(SOLDIER)+getPoupulationCount(KNIGTH);
	}

	@Override
	public String toString() {
		return "PopulationDistribution [count=" + count + ", distribution="
				+ distribution + "]";
	}
	

}
